package com.ts.proj.service.impl;

import com.ts.base.service.impl.CommonServiceImpl;
import com.ts.proj.entity.JijinDetailEntity;
import com.ts.proj.repository.JijinDetailRepository;
import com.ts.proj.service.JijinDetailService;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


//说明 字符串：，作为替换字符串 LOWERFinance                Finance

@Service
public class JijinDetailServiceImpl extends CommonServiceImpl<JijinDetailEntity>  implements JijinDetailService {

    @Autowired
    private JijinDetailRepository jijinDetailRepository;

    @Override
    public List<JijinDetailEntity> findAll(PageData pageData, Integer start, Integer length) {
        Specification<JijinDetailEntity> sp = this.getSpecification(pageData,JijinDetailEntity.class);
        Sort sort = new Sort(Sort.Direction.ASC,"id");
        Pageable pageable = new PageRequest(start, length, sort);
        return jijinDetailRepository.findAll(sp,pageable).getContent();
    }

    @Override
    public long count(PageData pageData) {
        Specification<JijinDetailEntity> sp = this.getSpecification(pageData,JijinDetailEntity.class);
        return jijinDetailRepository.count(sp);
    }

    @Override
    public boolean deleteByIds(Iterable<JijinDetailEntity> iterable) {
        jijinDetailRepository.deleteInBatch(iterable);
        return false;
    }

    @Override
    public List<JijinDetailEntity> saveAll(List<JijinDetailEntity> entities) {
        return jijinDetailRepository.saveAll(entities);
    }

    @Override
    public List<JijinDetailEntity> findAllById(Integer[] ids) {
        List<JijinDetailEntity> list = jijinDetailRepository.findAllById(Arrays.asList(ids));
        if(list.size()==0){
            JijinDetailEntity entity = new JijinDetailEntity();
            list.add(entity);
        }
        return list;
    }

    @Override
    public boolean deleteAll() {
        jijinDetailRepository.deleteAll();
        return false;
    }
}